package view;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.lang.management.ManagementFactory;
import java.net.InetAddress;
import java.net.UnknownHostException;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;

import model.GlobalParams;

public class SystemInformation extends JFrame {
	
	private static final long serialVersionUID = 1L;
	
	public SystemInformation(MainFrame f) {
		
		frame = f;
		
		tabbedpane = new JTabbedPane();	
		Hardware = new JPanel();
		Software = new JPanel();
		Network = new JPanel();
		
		str_Hardware = "Hardware";
		str_Software = "Software";
		str_Netwrok = "Network";
		
		configureHardware();
		configureSoftware();
		configureNetwork();
		
		tabbedpane.addTab(str_Hardware,Hardware);
		tabbedpane.addTab(str_Software,Software);
		tabbedpane.addTab(str_Netwrok,Network);		
		add(tabbedpane);
		
		
		setVisible(true);
		setMinimumSize(new Dimension(200,100));
		setResizable(false);
		setTitle("JCommander");
		setLocationRelativeTo(frame);
		
	}
	
	public void configureHardware() {		
		
		//String bios_version ;
		//String display_driver;
		String display_resoltution = Toolkit.getDefaultToolkit().getScreenSize().width + "x" +  Toolkit.getDefaultToolkit().getScreenSize().height ;
		String freememory = String.valueOf(Runtime.getRuntime().freeMemory());
		String installed_ram = String.valueOf(Runtime.getRuntime().totalMemory());
		
		Hardware.add(new JLabel("<html>"
			    //+  GlobalParams.getInstance().stringCollection.getHardware_bios_version() + "" + bios_version + "<br>"
			    //+  GlobalParams.getInstance().stringCollection.getHardware_display_driver() + "" + display_driver + "<br>"
			    +  "<font align=\"left\">"
			    +  GlobalParams.getInstance().stringCollection.getHardware_display_resolution() + " =  " + display_resoltution + "<br>"
			    +  GlobalParams.getInstance().stringCollection.getHardware_freememory() + " =  " + freememory +"<br>"
			    +  GlobalParams.getInstance().stringCollection.getHardware_installed_ram() + " =  " + installed_ram +"<br>"							
			    +  "</font>"
			    +
				"</html>"));
	}
	
	public void configureSoftware() {
		
		String free_memory = String.valueOf(Runtime.getRuntime().freeMemory());
		//String free_resources;
		String os = System.getProperty("os.name");
		String since_win_start = String.valueOf(ManagementFactory.getRuntimeMXBean().getStartTime());
		
		
		Software.add(new JLabel("<html>" 
				+  "<font align=\"left\">"
				+  GlobalParams.getInstance().stringCollection.getSoftware_free_memory() + " =  " + free_memory + "<br>"
				//+  GlobalParams.getInstance().stringCollection.getSoftware_free_resources() + "" + free_resources +"<br>"
				+  GlobalParams.getInstance().stringCollection.getSoftware_os() + " =  " + os + "<br>"
				+  GlobalParams.getInstance().stringCollection.getSoftware_time_since_win_start() + " =  " + since_win_start+ "<br>"
				+  "</font>"
				+
				"</html>"));
		
		
	}
	public void configureNetwork() {
		
		String computer_name = "";
		try {
			computer_name = InetAddress.getLocalHost().getHostName();
		} catch (UnknownHostException e) {			
			e.printStackTrace();
		}
		
		String domain = "";
		try {
			domain = InetAddress.getLocalHost().getHostAddress();
		} catch (UnknownHostException e) {			
			e.printStackTrace();
		}
		String user_name = System.getProperty("user.name");
		
		Network.add(new JLabel("<html>" 
				+  "<font align=\"left\">"
				+  GlobalParams.getInstance().stringCollection.getNetwork_computer_name() + " =  " + computer_name +"<br>"
				+  GlobalParams.getInstance().stringCollection.getNetwork_domain() + " =  " + domain +"<br>"
				+  GlobalParams.getInstance().stringCollection.getNetwork_user_name() + " =  " + user_name +"<br>"
				+  "</font>"
				+
				"</html>"));
	
	}
	
	
	private MainFrame frame;
	
	private JTabbedPane tabbedpane;
	private JPanel Hardware;
	private JPanel Software;
	private JPanel Network;
	
	String str_Hardware;
	String str_Software;
	String str_Netwrok;

}
